<div class="formElements">
    <div class="padding20px">
        <?php
        if ($classcoursetype == "classes") {
            $sendval = "classId";
            $thisclasscourse = "class";
        } else {
            $sendval = "courseId";
            $thisclasscourse = "course";
        }

        /*
          <div class="common">
          <div class="col">
          <input type="text" class="field" placeholder="Enter Name">
          </div>
          </div>
          <div class="common">
          <div class="col">
          <input type="text" class="field" placeholder="Enter Email">
          </div>
          </div> */
        ?>
        <input type="hidden" id='classreview_id' value="<?php echo $model->id; ?>">
        <div class="common">
            <div class="col">
                <textarea placeholder="Write Your Review" name="Reviews['reviews_text']" id="reviews_text" onkeyup ="countChar(this);"></textarea>
                <div class="errorMessage" id="error_reviews_text" style="display:none;">Please Write Your Review.</div>
                <div id="charNum" class="errorMessage"></div>
            </div>
        </div>
        <input type="button" class="btn twoBtn" value="Submit" id="submitLbtR"><a id="cancelRbtn" href="#" class="btn">Cancel</a>

    </div>
</div>


<script type="text/javascript" src="<?php echo ThemePath(); ?>/js/jquery.lightbox_me.js"></script>
<script>    
    $("#submitLbtR").click(function() {
        var text = $("#reviews_text").val();
        var classId = $("#classreview_id").val();
        if (text == '') {
            $("#error_reviews_text").show();
        } else {
            $.post("<?php echo Yii::app()->createUrl("Reviews/create"); ?>", {<?php echo $sendval; ?>: classId, text: text}, function(result) {
                if ($.trim(result) == 'redirect') {
                    openLoginReview();
                    return false;
                }
                if($.trim(result) == 'againsameuser') {
                    $("#reviews_text_success").hide();
                    $("#reviewDiv").hide();
                    $("#reviewEntryBox").show();
                    $("#error_reviews_text").show();
                    $("#error_reviews_text").text("You  have already made a query for this <?php echo $thisclasscourse; ?>.").show();
                    return false;
                }
                if ($.trim(result) == 'fail') {
                    $("#error_reviews_text").show();
                    $("#reviews_text_success").hide();
                    $("#error_reviews_text").text("You can't give own review.").show();
                    return false;
                }  
				
                if($.trim(result) != 'againsameuser' && $.trim(result) != 'fail'){
                    $("#reviewEntryBox").hide();
                    $("#error_reviews_text").hide();
                    $("#reviewDiv").show();
                    $("#reviews_text_success").text(result);
                }
            });
        }
    })
	
	
	
    function countChar(val) {
        var len = val.value.length;
        if (len >= 600) {
            val.value = val.value.substring(0, 600);
            $('#charNum').text('You can type max 600 char.');
        } else {
            $('#charNum').text('');
        }
    }
</script>



